/** 
 * Project Name:eleme-website 
 * File Name:GoodsDao.java 
 * Package Name:com.eleme.dao.impl 
 * Date:2017年12月26日下午4:24:37 
 * Copyright (c) 2017, fakedesigner@163.com All Rights Reserved. 
 * 
*/  
  
package com.eleme.dao.impl;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.eleme.dao.IBaseDao;
import com.eleme.dao.IDaoFactory;
import com.eleme.dao.IGoodsDao;
import com.eleme.dao.IMenuGoodsDao;
import com.eleme.entity.Goods;
import com.eleme.entity.Sample;
import com.eleme.entity.V_Menu_Goods;

/** 
 * ClassName:GoodsDao <br/> 
 * Function: TODO ADD FUNCTION. <br/> 
 * Reason:   TODO ADD REASON. <br/> 
 * Date:     2017年12月26日 下午4:24:37 <br/> 
 * @author   Pan 
 * @version   
 * @since    JDK 1.8 
 * @see       
 */
public class GoodsDao extends BaseDao<Goods> implements IGoodsDao, IMenuGoodsDao{

	
	public Goods createEntity() {
		return new Goods();
	}	
	
	public List<V_Menu_Goods> getMenuGoods(int shopid) {
		// TODO Auto-generated method stub
		PreparedStatement ps = null;
		ResultSet rs = null;
		V_Menu_Goods res = null;
		List<V_Menu_Goods> li = new ArrayList<V_Menu_Goods>();
		String sql = "Select shopid, goodsid, categoryid, name, photo, dtldesc, rate, monthlysold, spec, price "
				+ "From V_Menu_Goods Where shopid = ?";
		LOGGER.debug(sql);
		try {
			try {
				ps = getConnection().prepareStatement(sql);
				ps.setInt(1, shopid);
				rs = ps.executeQuery();
				if(rs != null) {
					while(rs.next()) {
						res = new V_Menu_Goods();
						res.setShopid(rs.getInt("shopid"));
						res.setGoodsid(rs.getInt("goodsid"));
						res.setCategoryid(rs.getInt("categoryid"));
						res.setName(rs.getString("name"));
						res.setPhoto(rs.getString("photo"));
						res.setDtldesc(rs.getString("dtldesc"));
						res.setRate(rs.getFloat("rate"));
						res.setMonthlysold(rs.getInt("monthlysold"));
						res.setSpec(rs.getInt("spec"));
						res.setPrice(rs.getFloat("price"));
						li.add(res);
					}
				}
			} finally {
				rs.close();
				ps.close();
			}
			
			
		} catch (SQLException e) {
			LOGGER.error("获取菜单商品失败：" + e.getMessage());
			e.printStackTrace();
		}
		
		return li;
	}	
	
	public List<V_Menu_Goods> getShopMenu(int shopid) {
		// TODO Auto-generated method stub
		return null;
	}



	public static void main(String[] args) {
		// TODO Auto-generated method stub
		GoodsDao s = new GoodsDao();
		List<V_Menu_Goods> li = s.getMenuGoods(1);
		System.out.println(li);

	}

}
